package vn.njai.thousand_english_word.Activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import butterknife.ButterKnife;
import butterknife.InjectView;
import vn.njai.thousand_english_word.R;

/**
 * Created by VUONG on 1/10/2015.
 */
public class GuildActivity extends Activity {
    private String TAG = "GuildActivity";
    private static String KEY_IS_FIRST_TIME = "GUILD_FIRST";
    private Context mContext;
    private int mPosition = 0;
    private boolean mIsFirstTime = false;

    @InjectView(R.id.btnBack) public ImageButton mBtnBack;
    @InjectView(R.id.btnNext) public ImageButton mBtnNext;
    @InjectView(R.id.imgGuild) public ImageView mImgGuild;

    public static void start(Context context, boolean isFirstTime) {
        Intent intent = new Intent(context,GuildActivity.class);
        intent.putExtra(KEY_IS_FIRST_TIME,isFirstTime);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guild);
        mIsFirstTime = getIntent().getBooleanExtra(KEY_IS_FIRST_TIME,false);
        mContext = getApplicationContext();
        init();
    }

    public void showInIndex(int index){
        mBtnBack.setVisibility(View.VISIBLE);
        mBtnNext.setVisibility(View.VISIBLE);

        if(index ==0){
            mBtnBack.setVisibility(View.GONE);
        }
        if(index ==4){
            if(mIsFirstTime)
                MainActivity.start(mContext);
            finish();
        }else {
            switch (index){
                case 0:
                    mImgGuild.setImageResource(R.drawable.image_guild_1000_1);
                    break;
                case 1:
                    mImgGuild.setImageResource(R.drawable.image_guild_1000_2);
                    break;
                case 2:
                    mImgGuild.setImageResource(R.drawable.image_guild_1000_3);
                    break;
                case 3:
                    mImgGuild.setImageResource(R.drawable.image_guild_1000_4);
                    break;
            }
            mImgGuild.requestLayout();
        }
    }

    public void init(){
        ButterKnife.inject(this);
        mPosition = 0;

        mBtnBack.setVisibility(View.GONE);
        mBtnNext.setVisibility(View.GONE);
        showInIndex(mPosition);
        View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()){
                    case R.id.btnBack:
                        mPosition -=1;
                        showInIndex(mPosition);
                        break;

                    case R.id.btnNext:
                        mPosition +=1;
                        showInIndex(mPosition);
                        break;
                }
            }
        };

        mBtnBack.setOnClickListener(onClickListener);
        mBtnNext.setOnClickListener(onClickListener);
    }
}
